package com.lancoo.answer.util.paperUtils.fragmentUtils.child;

import android.text.TextUtils;
import android.util.Log;

import androidx.fragment.app.Fragment;

import com.lancoo.answer.model.ConstantBean;
import com.lancoo.answer.model.bean.Child;
import com.lancoo.answer.model.bean.Item;
import com.lancoo.answer.model.bean.Ques;
import com.lancoo.answer.ui.child.lookReview.ChildClozeLookReviewFragment;
import com.lancoo.answer.ui.child.training.ChildBriefAnswerFragment;
import com.lancoo.answer.ui.child.training.ChildBriefListAnswerFragment;
import com.lancoo.answer.ui.child.training.ChildBriefNoAskAnswerFragment;
import com.lancoo.answer.ui.child.training.ChildSelectAnswerFragment;
import com.lancoo.answer.ui.child.training.ChildSpokenAnswerFragment;
import com.lancoo.answer.ui.child.training.ChildWordListenWriteAnswerFragment;
import com.lancoo.answer.view.fragment.composition.alternative.CompositionAlternativeAnswerFragment;
import com.lancoo.answer.ui.child.training.CompositionAnswerFragment;
import com.lancoo.answer.ui.ques.WaitToDockFragment;
import com.lancoo.answer.view.fragment.composition.continuation.CompositionContinuationAnswerFragment;
import com.lancoo.answer.view.fragment.dictation.PassageDictationAnswerFragment;
import com.lancoo.answer.view.fragment.fill.FillChildFragment;
import com.lancoo.answer.view.fragment.listenmatch.ListenMatchAnswerFragment;
import com.lancoo.answer.view.fragment.manual.ManualAnswerFragment;
import com.lancoo.answer.view.fragment.listenmatch.ListenParagraphFragment;
import com.lancoo.answer.view.fragment.option.MultiChildFragment;
import com.lancoo.answer.view.fragment.translate.TranslateChapterAnswerFragment;

/**
 * Created by pengmi on 2022/2/20 11:49
 * Description:小题可作答状态状态fragment加载
 */
public class ChildTrainingingFragmentUtils {

    public static Fragment loadChildTrainingFragment(Ques ques,
                                                     int typeIndex,
                                                     int quesIndex,
                                                     int childIndex,
                                                     int defaultLoadIndex,int defaultLoadChildexIndex,int defaultLoadItemIndex) {
        String genreID = ques.getGenreID();
        String typeNo = ques.getTypeNo();
        Child child = ques.getChildList().get(childIndex);
        Item item = child.getItemList().get(0);
        int childAnswerType = child.getChildAnswerType();
        if (ques.getSpecialAnswerMethod() == 1) {
            return ChildSpokenAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
        }
        if (ConstantBean.Companion.getTaskControlBean().isManu()) {//人工组卷特殊适配
            switch (typeNo) {
                case "f"://作文题
                    return ManualAnswerFragment.loadQueseFragment(typeIndex, quesIndex, childIndex);
            }

        }
        switch (typeNo) {
            case "f"://作文题
                if (TextUtils.equals("52", genreID)) {//二选一作文
                    return CompositionAlternativeAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                }
                if (TextUtils.equals("34", genreID) && item.getItemAskList() != null &&
                        item.getItemAskList().size() > 0) {//读后续写
                    return CompositionContinuationAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                }
                return CompositionAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
            case "W"://短文听写
                return PassageDictationAnswerFragment.loadQueseFragment(typeIndex, quesIndex, childIndex);
            case "S"://听力填空
                return FillChildFragment.Companion.loadFragment(typeIndex, quesIndex, childIndex, defaultLoadItemIndex);
            case "C"://语法选择，完形填空，对话选择
                return ChildClozeLookReviewFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
            case "x"://听力匹配  听力排序，
                return ListenParagraphFragment.Companion.loadFragment(typeIndex, quesIndex, defaultLoadItemIndex);
            case "L"://听力综合
                return ListenMatchAnswerFragment.Companion.loadFragment(typeIndex, quesIndex, childIndex, defaultLoadIndex);
            case "X"://阅读简答
                if (TextUtils.equals(ques.getSpecialFeatureCodes(), "107")) {//拓展表达
                    switch (childAnswerType) {
                        case 3:
                            return ChildBriefAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 0);
                        case 4:
                            return CompositionAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                    }
                }
                return ChildBriefAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 0);
            case "V"://连词成句
                return ChildBriefAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 0);
            case "k"://综合匹配（匹配加简答、匹配加选择、一题多空、一题一空）
                switch (childAnswerType) {
                    case 0:
                        return ChildSelectAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                    case 1:
                        return MultiChildFragment.Companion.loadFragment(typeIndex, quesIndex, childIndex);//等待对接
                    case 2:
                    case 3:
                        return ChildBriefListAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 0);
                }
            case "G"://听力简答
                return ChildBriefListAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 0);
        }
        switch (genreID) {
            case "20": //选词填空
            case "21": //句子填空
            case "22": //翻译填空
                return FillChildFragment.Companion.loadFragment(typeIndex, quesIndex, childIndex, defaultLoadIndex);
            case "39"://篇章翻译英译中
                if (item.getItemAskList() == null || item.getItemAskList().size() == 0) {
                    return ChildBriefNoAskAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 1);
                }
                return TranslateChapterAnswerFragment.loadQueseFragment(typeIndex, quesIndex, childIndex, 1);
            case "41"://篇章翻译中译英
                if (item.getItemAskList() == null || item.getItemAskList().size() == 0) {
                    return ChildBriefNoAskAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 0);
                }
                return TranslateChapterAnswerFragment.loadQueseFragment(typeIndex, quesIndex, childIndex, 0);
            case "38"://句子英译中
            case "25"://英译中
                return ChildBriefAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 1);
            case "40"://句子中译英
            case "26"://中译英
                return ChildBriefAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 0);
            case "51"://句子定向中译英
                return ChildBriefNoAskAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 0);
            case "50"://句子定向英译中
                return ChildBriefNoAskAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 1);
            case "VD"://词汇听写
                return ChildWordListenWriteAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
            case "78"://复合写作
                switch (childAnswerType) {
                    case 3:
                        return ChildBriefNoAskAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 0);
                    case 4:
                        return CompositionAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                }
            case "0"://拓展表达
                switch (childAnswerType) {
                    case 3:
                        return ChildBriefAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 0);
                    case 4:
                        return CompositionAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                }
            case "98"://看情景写句子
            case "99"://看图写句子
                return ChildBriefAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 0);
            case "107"://词汇翻译
                return ChildBriefListAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 1);
        }

        switch (childAnswerType) {
            case 1:
                return ChildSelectAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
            case 2:
                return FillChildFragment.Companion.loadFragment(typeIndex, quesIndex, childIndex, defaultLoadIndex);
            case 4:
                return ChildBriefAnswerFragment.loadChildFragment(typeIndex, quesIndex, childIndex, 0);
            default:
                return new WaitToDockFragment();
        }
    }
}
